package com.globallogic.dailyplanner.jsfbeans;

import java.util.Map;

import javax.faces.bean.ManagedBean;
import javax.faces.context.FacesContext;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import com.globallogic.dailyplanner.dto.User;
import com.globallogic.dailyplanner.service.UserService;

@Controller
@ManagedBean
public class ProfileInfoBean {
	
	@Autowired
	private UserService userService;
	private User user;
	
	//TODO find way to take id param from jsf to bean more correctly
	private void initUser(){
		Map<String, String> params =  FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap();
		int id = Integer.valueOf(params.get("userId"));
		
		user = userService.getById(id);
	}
	
	public User getUser() {
		initUser();
		
		return user;
	}
	public void setUser(User user) {
		this.user = user;
	}
}
